#include <sys/socket.h>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/un.h>


int main(){
    int sockfd=socket(AF_LOCAL,SOCK_STREAM,0);
    if(sockfd<0){
        perror("socket error");
        exit(1);
    }
    //本地通信与网络通信的不同
    struct sockaddr_un addr;
    addr.sun_family=AF_LOCAL;
    strcpy(addr.sun_path,"/tmp/ymbxsock");
    
    int ret=connect(sockfd,(struct sockaddr*)&addr,sizeof(addr));
    if(ret<0){
        perror("connect error");
        exit(2);
    }
    char buffer[1024];
    while(1){
        memset(buffer,0,sizeof(buffer));
        printf("client say:");
        fflush(stdout);
        fgets(buffer,sizeof(buffer)-1,stdin);
        ssize_t n=write(sockfd,buffer,strlen(buffer));
        if(n<=0){
            perror("write error");
            break;
        }
        if(strncmp(buffer,"quit",4)==0){
            break;
        }
    }

    return 0;
}